package com.mingdao.lhy.controller;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mingdao.lhy.biz.WishFillingBiz;
import com.mingdao.lhy.pojo.ExamResult;
import com.mingdao.lhy.pojo.Score;
import com.mingdao.lhy.pojo.SignUpStudent;
import com.mingdao.lhy.service.WishFillingService;

@Controller
@RequestMapping(value = "doQueryScore")
public class ExamResultController {
	private static Logger log = LoggerFactory.getLogger(ExamResultController.class);

	@Autowired
	private WishFillingService wishFillingService;

	@Autowired
	private WishFillingBiz wishFillingBiz;

	@Autowired
	private HttpSession session;

	/**
	 * 查询成绩页面
	 * 
	 * @return
	 */
	@RequestMapping("")
	public String index(Model model, @RequestParam("bmh") String bmh) {

		session = wishFillingBiz.getSession();
		if (null == session || null == session.getAttribute("student")) {
			session = null;
			log.error("用户未登录，请重新登录");
			return "redirect:/";
		}
		SignUpStudent student = (SignUpStudent) session.getAttribute("student");
		if (null == bmh || !bmh.equals(student.getBmh())) {
			session = null;
			log.error("用户请求数据不一致，请重新登录");
			return "redirect:/";
		}

		log.debug("进入【志愿填报页面】");
		if (null == student || null == student.getBmh() || student.getBmh().isEmpty()) {
			// model.addAttribute("student",student);
			log.warn("学生信息为空，需要重新登录");
			return "loginStudent";
		}

		model.addAttribute("student", student);

		/**
		 * 查成绩
		 */
		Score examResult=new Score();
		examResult = wishFillingService.queryExamResultByBmh(bmh);
		if (null == examResult ) {
			// model.addAttribute("student",student);
			log.warn("无该生成绩");
			model.addAttribute("msg", "无成绩信息 ");
			return "/transform";
			 
		}
   		model.addAttribute("score", examResult);

		return "queryScore";
	}

}
